home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / quad.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-13  |  1.7 KB  |  80 lines  |  [TEXT/CWIE]

  1. #include "quad.h"
  2.  
  3. /* see quad.h for more information */
  4.  
  5. void q_setColor4fv( Quad *q, int index, float color[4]) {
  6.   memcpy(q->vertex[index].color, color, 4 * sizeof(float));
  7. }
  8.  
  9. void q_setColor4f( Quad *q, int index, float r, float g, float b, float a) {
  10.   q->vertex[index].color[0] = r;
  11.   q->vertex[index].color[1] = g;
  12.   q->vertex[index].color[2] = b;
  13.   q->vertex[index].color[3] = a;
  14. }
  15.  
  16. void q_setColor3f( Quad *q, int index, float r, float g, float b) {
  17.   q_setColor4f( q, index, r, g, b, 1.0);
  18. }
  19.  
  20. void q_setTexCoord2f( Quad *q, int index, float u, float v ) {
  21.   q->vertex[index].uv[0] = u;
  22.   q->vertex[index].uv[1] = v;
  23. }
  24.  
  25. void q_setVertex3f( Quad *q, int index, float x, float y, float z) {
  26.   q->vertex[index].v[0] = x;
  27.   q->vertex[index].v[1] = y;
  28.   q->vertex[index].v[2] = z;
  29. }
  30.  
  31. QuadBuffer* createQuadBuffer(int size) {
  32.   QuadBuffer *q;
  33.   q = (QuadBuffer*) malloc(sizeof(struct QuadBuffer));
  34.   if(q != NULL) {
  35.     q->quads = (Quad*) malloc(sizeof(struct Quad) * size);
  36.     if(q->quads != 0) {
  37.       q->size = size;
  38.       q->current = 0;
  39.       return q;
  40.     } else free(q);
  41.   }
  42.   fprintf(stderr, "failed to allocate quad buffer\n");
  43.   exit(2);
  44. }
  45.  
  46. void freeQuadBuffer(QuadBuffer *q) {
  47.   free(q->quads);
  48.   free(q);
  49. }
  50.  
  51. extern Quad *getNextQuad(QuadBuffer *q) {
  52.   if(q->current < q->size)
  53.     return q->quads + q->current++;
  54.   else {
  55.     fprintf(stderr, "quad buffer overflow!\n");
  56.     return NULL;
  57.   }
  58. }
  59.  
  60. int getCurrentQuad(QuadBuffer *q) {
  61.   return q->current;
  62. }
  63.  
  64.  
  65. int getQuadBufferSize(QuadBuffer *q) {
  66.   return q->size;
  67. }
  68.  
  69. void q_setType(Quad *q, int type) {
  70.   q->type = type;
  71. }
  72.  
  73. Quad* getQuadAt(QuadBuffer *q, int index) {
  74.   return q->quads + index;
  75. }
  76.  
  77. void renderQuadAt(QuadBuffer *q, int* index, int i) {
  78.   renderQuad(q->quads + index[i]);
  79. }
  80.